columnview: Add gtk_column_view_add_row_factory()
authorBenjamin Otte <otte@redhat.com>
Wed, 29 Mar 2023 08:36:18 +0000 (10:36 +0200)
committerBenjamin Otte <otte@redhat.com>
Sat, 1 Apr 2023 18:49:40 +0000 (20:49 +0200)
This allows setting a factory to toggle per-row properties.

Implemented are selectable, focusable and activatable.
These are meant to supercede the per-cell selectable and activatable
properties, which make no sense individually.

The focus property makes it possible to focus rows instead of cells,
which is the default behavior.

gtk/gtkcolumnview.c
gtk/gtkcolumnview.h

index addb92ef32c8749b7b5f6ea2cc324b253a460a29..5437d684c45ad96145e54eb178bb26c77ce6dba5 100644 (file)
@@ -223,6 +223,7 @@ enum
   PROP_HSCROLL_POLICY,
   PROP_MODEL,
   PROP_REORDERABLE,
+  PROP_ROW_FACTORY,
   PROP_SHOW_ROW_SEPARATORS,
   PROP_SHOW_COLUMN_SEPARATORS,
   PROP_SINGLE_CLICK_ACTIVATE,
@@ -635,6 +636,14 @@ gtk_column_view_get_property (GObject    *object,
       g_value_set_object (value, gtk_list_view_get_model (self->listview));
       break;
 
+    case PROP_REORDERABLE:
+      g_value_set_boolean (value, gtk_column_view_get_reorderable (self));
+      break;
+
+    case PROP_ROW_FACTORY:
+      g_value_set_object (value, gtk_column_view_get_row_factory (self));
+      break;
+
     case PROP_SHOW_ROW_SEPARATORS:
       g_value_set_boolean (value, gtk_list_view_get_show_separators (self->listview));
       break;
@@ -659,10 +668,6 @@ gtk_column_view_get_property (GObject    *object,
       g_value_set_boolean (value, gtk_column_view_get_single_click_activate (self));
       break;
 
-    case PROP_REORDERABLE:
-      g_value_set_boolean (value, gtk_column_view_get_reorderable (self));
-      break;
-
     case PROP_TAB_BEHAVIOR:
       g_value_set_enum (value, gtk_list_view_get_tab_behavior (self->listview));
       break;
@@ -718,6 +723,14 @@ gtk_column_view_set_property (GObject      *object,
       gtk_column_view_set_model (self, g_value_get_object (value));
       break;
 
+    case PROP_REORDERABLE:
+      gtk_column_view_set_reorderable (self, g_value_get_boolean (value));
+      break;
+
+    case PROP_ROW_FACTORY:
+      gtk_column_view_set_row_factory (self, g_value_get_object (value));
+      break;
+
     case PROP_SHOW_ROW_SEPARATORS:
       gtk_column_view_set_show_row_separators (self, g_value_get_boolean (value));
       break;
@@ -746,10 +759,6 @@ gtk_column_view_set_property (GObject      *object,
       gtk_column_view_set_single_click_activate (self, g_value_get_boolean (value));
       break;
 
-    case PROP_REORDERABLE:
-      gtk_column_view_set_reorderable (self, g_value_get_boolean (value));
-      break;
-
     case PROP_TAB_BEHAVIOR:
       gtk_column_view_set_tab_behavior (self, g_value_get_enum (value));
       break;
@@ -826,6 +835,28 @@ gtk_column_view_class_init (GtkColumnViewClass *klass)
                          GTK_TYPE_SELECTION_MODEL,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+  /**
+   * GtkColumnView:reorderable: (attributes org.gtk.Property.get=gtk_column_view_get_reorderable org.gtk.Property.set=gtk_column_view_set_reorderable)
+   *
+   * Whether columns are reorderable.
+   */
+  properties[PROP_REORDERABLE] =
+    g_param_spec_boolean ("reorderable", NULL, NULL,
+                          TRUE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+  /**
+   * GtkColumnView:row-factory: (attributes org.gtk.Property.get=gtk_column_view_get_row_factory org.gtk.Property.set=gtk_column_view_set_row_factory)
+   *
+   * The factory used for configuring rows.
+   *
+   * Since: 4.12
+   */
+  properties[PROP_ROW_FACTORY] =
+    g_param_spec_object ("row-factory", NULL, NULL,
+                         GTK_TYPE_LIST_ITEM_FACTORY,
+                         G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
   /**
    * GtkColumnView:show-row-separators: (attributes org.gtk.Property.get=gtk_column_view_get_show_row_separators org.gtk.Property.set=gtk_column_view_set_show_row_separators)
    *
@@ -866,16 +897,6 @@ gtk_column_view_class_init (GtkColumnViewClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
-  /**
-   * GtkColumnView:reorderable: (attributes org.gtk.Property.get=gtk_column_view_get_reorderable org.gtk.Property.set=gtk_column_view_set_reorderable)
-   *
-   * Whether columns are reorderable.
-   */
-  properties[PROP_REORDERABLE] =
-    g_param_spec_boolean ("reorderable", NULL, NULL,
-                          TRUE,
-                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
-
   /**
    * GtkColumnView:tab-behavior: (attributes org.gtk.Property.get=gtk_column_view_get_tab_behavior org.gtk.Property.set=gtk_column_view_set_tab_behavior)
    *
@@ -1997,6 +2018,53 @@ gtk_column_view_get_enable_rubberband (GtkColumnView *self)
   return gtk_list_view_get_enable_rubberband (self->listview);
 }
 
+/**
+ * gtk_column_view_set_row_factory: (attributes org.gtk.Method.set_property=row-factory)
+ * @self: a `GtkColumnView`
+ * @factory: (nullable): The row factory
+ *
+ * Sets the factory used for configuring rows. The factory must be for configuring
+ * [class@Gtk.ColumnViewRow] objects.
+ *
+ * If this factory is not set - which is the default - then the defaults will be used.
+ *
+ * This factory is not used to set the widgets displayed in the individual cells. For
+ * that see [method@GtkColumnViewColumn.set_factory] and [class@GtkColumnViewCell].
+ *
+ * Since: 4.12
+ */
+void
+gtk_column_view_set_row_factory (GtkColumnView      *self,
+                                 GtkListItemFactory *factory)
+{
+  g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
+
+  if (factory == gtk_list_view_get_factory (self->listview))
+    return;
+
+  gtk_list_view_set_factory (self->listview, factory);
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ROW_FACTORY]);
+}
+
+/**
+ * gtk_column_view_get_row_factory: (attributes org.gtk.Method.get_property=row-factory)
+ * @self: a `GtkColumnView`
+ *
+ * Gets the factory set via [method@Gtk.ColumnView.set_row_factory].
+ *
+ * Returns: (nullable) (transfer none): The factory
+ *
+ * Since: 4.12
+ */
+GtkListItemFactory *
+gtk_column_view_get_row_factory (GtkColumnView *self)
+{
+  g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), FALSE);
+
+  return gtk_list_view_get_factory (self->listview);
+}
+
 /**
  * gtk_column_view_set_tab_behavior: (attributes org.gtk.Method.set_property=tab-behavior)
  * @self: a `GtkColumnView`
index aa04cd9363a6a597b215344e1c3a239be0967406..afccfcfd9d45f3eb62a097a4d646c0b6444877f4 100644 (file)
@@ -114,5 +114,12 @@ void            gtk_column_view_set_tab_behavior                (GtkColumnView
 GDK_AVAILABLE_IN_4_12
 gboolean        gtk_column_view_get_tab_behavior                (GtkColumnView          *self);
 
+GDK_AVAILABLE_IN_4_12
+void            gtk_column_view_set_row_factory                 (GtkColumnView          *self,
+                                                                 GtkListItemFactory     *factory);
+GDK_AVAILABLE_IN_4_12
+GtkListItemFactory *
+                gtk_column_view_get_row_factory                 (GtkColumnView          *self);
+
 G_END_DECLS